<include file="public@header" />
</head>

<body>
    <div class="wrap">
        <ul class="nav nav-tabs">
            <li class="active"><a>编辑组长</a></li>
        </ul>
        <form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('leader/edit')}"
            enctype="multipart/form-data">


            <!-- <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    <span class="form-required">*</span>姓名
                </label>
                <div class="col-md-6 col-sm-10">
                    <input type="text" class="form-control" name="name" value="{$res['name']}">
                </div>
            </div> -->

            <div class="form-group">
                <label class="col-sm-2 control-label">
                    <span class="form-required">*</span>姓名
                </label>
                <div class="col-md-6 col-sm-10">
                    <select name="name" id="nameSelect" class="form-control">
                        <option value=""></option>
                        <volist name="group" id="v">
                            //<option value="{$v.name}">{$v.name}</option>
                            <option value="{$v.name}" <if condition="$v.name eq $res['name']">selected</if>>{$v.name}
                            </option>
                        </volist>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">
                    <span class="form-required">*</span>工种
                </label>
                <div class="col-md-6 col-sm-10">
                    <input name="type" id="typeSelect" class="form-control" value="{$res['type']}" />

                    <!-- <select name="type" id="typeSelect" class="form-control">
                        <option value=""></option>
                        <volist name="group" id="v">
                            <option value="{$v.type}">{$v.type}</option>
                        </volist>
                    </select> -->
                </div>
            </div>

            <!-- 
            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    <span class="form-required">*</span>工种
                </label>
                <div class="col-md-6 col-sm-10">
                    <input type="text" class="form-control" name="type" value="{$res['type']}">
                </div>
            </div> -->



            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    <span class="form-required">*</span>入职时间
                </label>
                <div class="col-md-6 col-sm-10">
                    <input type="date" class="form-control" name="insTime" value="{$res['insTime']}">
                </div>
            </div>

            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    离职时间
                </label>
                <div class="col-md-6 col-sm-10">
                    <input type="date" class="form-control" name="outTime" value="{$res['outTime']}">
                </div>
            </div>
            <input type="hidden" name="id" value="{$res['id']}">


            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
                    <a class="btn btn-default" href="javascript:history.back(-1);">{:lang('BACK')}</a>
                </div>
            </div>
        </form>
    </div>
    <script src="__STATIC__/js/admin.js"></script>
    <script>
        // 输出姓名与工种的映射
        var nameTypeMap = {
            <volist name="group" id="v" >
                "{$v.name}": "{$v.type}" <if condition = "$i neq count($group)" >,</if>
            </volist >
        };

        var nameSelect = document.getElementById('nameSelect');
        var typeSelect = document.getElementById('typeSelect');

        nameSelect.addEventListener('change', function () {
            var name = this.value;
            var type = nameTypeMap[name] || '';
            typeSelect.value = type;
        });

        // 页面加载时自动设置工种（如果有值）
        window.onload = function () {
            var name = nameSelect.value;
            if (name && nameTypeMap[name]) {
                typeSelect.value = nameTypeMap[name];
            }
        };
    </script>
</body>

</html>